package com.hxx.day8;

import org.junit.Test;

import java.util.List;

/**
 * Reduce计算
 */
public class TestDemo6 {
    @Test
    public void test1(){
        List.of(1,2,3,4,5)
                .stream()
                .reduce((x,y)->x+y)
                .ifPresent(System.out::println);
    }
    /**
     * 实体类的属性计算
     */
     @Test
    public void test2(){
        List.of(new Book(1,"三国演义",100,"中国"),
                new Book(2,"水浒传",200,"中国"),
                new Book(3,"西游记",300,"中国"))
                .stream()
                .map(Book::getPrice)
                .reduce(Double::sum)//reduce((x,y)->x+y)
                .ifPresent(System.out::println);
    }
}
































